<template>
  <view
    class="cu-avatar lg"
    :class="appSetting.circleAvatar ? 'round' : 'radius'"
    @tap="openUserInfo(info)"
    :style="[{ backgroundImage: `url(${bgUrl() + '?imageView2/1/w/100/h/100/q/100'})` }]"
  ></view>
  <!-- 'url(' + info.avatar + ')' -->
  <!-- `url(${changeInfoNum ? info[changeInfoNum]['avatar'] : info.avatar})` -->
</template>
<script>
const userInfo = uni.getStorageSync('userInfo');
// const appSetting = uni.getStorageSync('appSetting');
import { useMsgStore } from '@/store/message';
import pinia from '@/store/index';
const msgStore = useMsgStore(pinia);
import { useloginStore } from '@/store/login';
const userStore = useloginStore(pinia);
export default {
  name: 'im-touch',
  props: {
    info: {
      type: Object,
      default: function () {
        return {};
      }
    },
    circleAvatar: { type: Boolean, default: false },
    self: { type: Boolean, default: false },
    cut: { type: Boolean, default: false },
    changeInfoNum: { type: Number, default: 0 },
    is_group: { type: String, default: '' }
  },
  data() {
    return {
      toucheTimer: 0,
      fingerRes: [],
      distance: 0,
      taptimer: 100,
      appSetting: userStore.appSetting
    };
  },

  methods: {
    bgUrl() {
      if (this.self) {
        return this.info.avatar;
      } else {
        if (this.changeInfoNum >= 2 && this.cut) {
          return this.info[this.changeInfoNum]['avatar'];
        } else {
          return this.info[0]['avatar'];
        }
      }
    },
    // 打开用户详情
    openUserInfo(item) {
      // let friend = msgStore.getContact(item.user_id);
      // if (!this.profile && !friend) {
      //   uni.showToast({
      //     title: '已开启用户隐私！',
      //     icon: 'none'
      //   });
      //   return false;
      // }
      if (item.id == userInfo.user_id || item.identity == 1) return;
      uni.navigateTo({
        // url: '/pages/contacts/detail?id=' + this.info.id
        url: `/pages/contacts/detail?id=${this.info.id}&source=group&group_id=${this.is_group}`
      });
    }
  }
};
</script>
<style scoped lang="scss">
// .cu-avatar {
//   border-radius: 50%;
// }
</style>
